<?php
/**
 * User: Administrator
 * Time: 2015/10/27 16:26
 */


$dom = new DOMDocument();
$dom->encoding = 'UTF-8';

//$dom->load('./test.xml');
//
////通过id获取节点对象
////$cd = $dom->getElementById('24');
////通过节点名获取节点对象
//$cd = $dom->getElementsByTagName('cd');
////遍历节点
//for ($i = 0; $i < $cd->length; $i++) {
//	echo $cd->item($i)->nodeValue . "\n";
//}
//
//echo memory_get_usage();


//创建文档节点
$collection = $dom->createElement('collection');
$dom->appendChild($collection);

for($i=0;$i<1000;$i++){
	$cd = $dom->createElement('cd');
	$title = $dom->createElement('title', '港台明星'.rand(1,1000));
	$type        = $dom->createAttribute('type');
	$type->value = 'hk'.rand(1,1000);
	$title->appendChild($type);
	$artist = $dom->createElement('artist', '刘德华'.rand(1,1000));
	$year   = $dom->createElement('year', '1995'.rand(1,1000));
	$cd->appendChild($title);
	$cd->appendChild($artist);
	$cd->appendChild($year);
	$collection->appendChild($cd);
}
//生成一个xml文档
echo $dom->save('test.xml');





